﻿using System;
using System.Activities;
using System.ComponentModel;
using System.Collections.Generic;
using System.Reflection;

namespace Vision.Core.ActivityComponents.Services
{
    /// <summary>
    /// 
    /// </summary>
    [System.ComponentModel.Designer(typeof(WebServiceGetAvailableMethodsDesigner))]
    public class WebServiceGetAvailableMethods : NativeActivity
    {
        /// <summary>
        /// 
        /// </summary>
        [Browsable(false)]
        [DefaultValue(null)]
        public ActivityAction<MethodInfo> Body { get; set; }
                
        /// <summary>
        /// 
        /// </summary>
        public WebServiceGetAvailableMethods()
        {
            this.Body = new ActivityAction<MethodInfo>(){
                Argument = new DelegateInArgument<MethodInfo>() { Name = "method" }
            };
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="context"></param>
        protected override void Execute(NativeActivityContext context)
        {
            Components.DynamicWebService dynamicWebService = (Components.DynamicWebService)context.Properties.Find("9d40e1ff-4d19-46c1-a77e-348a229c6acc");
            if (dynamicWebService != null){
                foreach (var method in dynamicWebService.GetServiceMethods()){
                    context.ScheduleAction(this.Body, method);    
                }                                
            }
        }
    }
}
